Version information


You can add version information into your Delphi applications using Project/Options/Version
info. This information stored as a resource in your executable file. You can get
this information from Windows EXE files and DLLs, below function can be used to extract
some version information such as major version, minor version, release, and build.

function GetFileVersion(FileName: string; var
Major, Minor, Release, Build: Word): Boolean;
var
Size, Size2: DWord;
Pt, Pt2: Pointer;
begin
Result:= False;
   (*** Get version information size in exe ***)
 Size:=
   GetFileVersionInfoSize(PChar(FileName),
     Size2);
    (*** Make sure that version information is  include in exe
     file ***)
 if Size > 0 then
begin
  GetMem(Pt, Size);
  GetFileVersionInfo(PChar(FileName),
    0, Size, Pt);
  VerQueryValue(Pt, '\', Pt2, Size2);
  with TVSFixedFileInfo(Pt2^) do
  begin
    Major:= HiWord(dwFileVersionMS);
    Minor:= LoWord(dwFileVersionMS);
    Release:= HiWord(dwFileVersionLS);
    Build:= LoWord(dwFileVersionLS);
  end;
  FreeMem(Pt, Size);
  Result:= True;
end; // if Size > 0

end;


Example of using this function:

var
Major, Minor, Release, Build: Word;
begin
if
GetFileVersion(Edit1.Text, Major, Minor,
  Release, Build)
then
 Label1.Caption:= Format('%d.%d.%d.%d',
   [Major, Minor, Release, Build])
else
  Label1.Caption:= 'Version information ' +
   'not included in this file';
end;